package com.blunka.framework.client.ui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.UIManager;

import com.blunka.framework.client.constants.ImageConstant;
import com.blunka.framework.client.constants.InitDesignConfig;
import com.blunka.framework.client.ui.tools.BkfmShortCutkey;

/**
 *
 *
 * @平台：统一开发平台
 * @文件名称：MainFrame.java
 * @文件描述：设计器主窗体界面
 * @author xuqiang
 * @日期：2018年5月25日下午2:56:44
 *
 */
public class MainFrame extends JFrame{

	public static MainFrame mainFrame = new MainFrame();
	private JSplitPane hSplitPane;

	public static MainFrame newInstance(){
		return mainFrame;
	}

	public static MainFrame getMainFrame(){
		return mainFrame;
	}

	private MainFrame(){

		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

			super.setTitle(InitDesignConfig.getDesignerName()+"-"+InitDesignConfig.getDesignerVersion());
			Container container= getContentPane();
			container.setLayout(new BorderLayout());
			Dimension  displaySize = Toolkit.getDefaultToolkit().getScreenSize();
			super.setSize(displaySize.getSize());
			initFrame(container);
			Image img = Toolkit.getDefaultToolkit().getImage(ImageConstant.ICON_IMG);
			super.setIconImage(img);
			super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			super.setExtendedState(JFrame.MAXIMIZED_BOTH);
			super.setVisible(true);
			//设置百分比例
			hSplitPane.setDividerLocation(0.3);
			//添加快捷键
			BkfmShortCutkey.initShirtCutKey();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void initFrame(Container container){
		container.add(ToolBarMenu.newInstance(), BorderLayout.NORTH);
		hSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

		hSplitPane.setRightComponent(MainPanel.newInstance());
		hSplitPane.setLeftComponent(new JScrollPane(TreeModelPanel.newInstance()));


		hSplitPane.setOneTouchExpandable(true);
		container.add(hSplitPane,BorderLayout.CENTER);
		container.add(StatusBar.newInstance(), BorderLayout.SOUTH);

		this.setJMenuBar(FrameMenu.newInstance());
	}
}
